package net.vkits.api;

import io.swagger.annotations.*;
import net.vkits.admin.domain.model.Post;
import net.vkits.admin.domain.model.SubPost;
import net.vkits.common.dto.BaseDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * Created by ethan-liu on 2017/2/18.
 */
@Api(value = "posts", description = "the posts API")
@RequestMapping("/api/v2")
public interface PostsApi {

    @ApiOperation(value = "return post list", notes = "return post list", response = Post.class, responseContainer = "List", tags={ "posts", })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "return post list", response = Page.class),
            @ApiResponse(code = 404, message = "something wrong", response = Post.class) })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query",
                    value = "Results page you want to retrieve (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query",
                    value = "Number of records per page.")
    })
    @RequestMapping(value = "/posts/list",
            produces = { "application/json" },
            method = RequestMethod.GET)
    @ResponseBody
    Page<Post> postsGetByParam(@ApiIgnore @PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC)Pageable pageable);

    @ApiOperation(value = "add post", notes = "add post", response = BaseDTO.class, tags={ "posts", })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "return 200 info", response = BaseDTO.class),
            @ApiResponse(code = 404, message = "something wrong", response = BaseDTO.class) })
    @RequestMapping(value = "/posts",
            produces = { "application/json" },
            method = RequestMethod.PUT)
    ResponseEntity<BaseDTO> addPost(@ApiParam(value = "发帖内容", required = true) @RequestBody Post post);

    @ApiOperation(value = "get post info", notes = "get post info", response = Post.class, tags={ "posts", })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "return post info", response = Post.class),
            @ApiResponse(code = 404, message = "something wrong", response = BaseDTO.class) })
    @RequestMapping(value = "/posts/detail/{id}",
            produces = { "application/json" },
            method = RequestMethod.GET)
    ResponseEntity<Post> getPost(@ApiParam(value = "主贴ID", required = true) @PathVariable Long id);

    @ApiOperation(value = "add subpost", notes = "add subpost", response = BaseDTO.class, tags={ "posts", })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "return 200 info", response = BaseDTO.class),
            @ApiResponse(code = 404, message = "something wrong", response = BaseDTO.class) })
    @RequestMapping(value = "/posts/sub",
            produces = { "application/json" },
            method = RequestMethod.PUT)
    ResponseEntity<BaseDTO> addSubPost(@ApiParam(value = "评论内容", required = true) @RequestBody SubPost subPost);

    @ApiOperation(value = "update like number", notes = "点赞", response = BaseDTO.class, tags={ "posts", })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "点赞成功", response = BaseDTO.class),
            @ApiResponse(code = 404, message = "点赞失败", response = BaseDTO.class) })
    @RequestMapping(value = "/posts/like/{id}",
            produces = { "application/json" },
            method = RequestMethod.PUT)
    ResponseEntity<BaseDTO> likePost(@ApiParam(value = "主贴ID", required = true) @PathVariable Long id);
}
